<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
	
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>

<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.services.AddSectionService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Section - Teacher Settings</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" ></jsp:include>


<link rel="stylesheet" href="<%=request.getContextPath()%>/views/css/ui/jquery-ui-1.10.4.custom.min.css">
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.core.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.widget.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.accordion.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.datepicker.js"></script>
<script>
	/* If want to fix height inner content of accordion - 
		remove 'heightStyle' line (and the above comma too :p ).
	*/
	$(function() {
		$( "#accordion" ).accordion({
			collapsible: true,
			heightStyle: "content",
		});
	});
</script>
<script>
	$(function() {
		$( "#teacher_dob" ).datepicker({
			dateFormat: 'yy-mm-dd'
		});
	});
	$(function() {
		$( "#teacher_doj" ).datepicker({
			dateFormat: 'yy-mm-dd'
		});
	});
</script>

</head>

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp"></jsp:include>
<jsp:include page="../common/checkSectionRole.jsp" />

<% String currentUser = (String) session.getAttribute("currentUser");%>

<%-- AddSectionService addSectionService = new AddSectionService();%>
<% String deptId = (addSectionService.getSectionByDeptEmail(currentUser)).getDept_id(); --%>
	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">

				
				<div>
					<form action="<%=request.getContextPath()%>/views/section/addTeacher.jsp">
						<input type="submit" value="Add Teacher" class="button add_button">
					</form>
					
				</div>
				<span class="success_msg">${teacherUpdated}</span>
				<span class="error_msg">${teacherNotUpdated}</span>
				<span class="error_msg">${isClassTeacherDeleted}</span>
				<span class="success_msg">${teacherDeleted}</span>
				<span class="error_msg">${teacherNotDeleted}</span>
				<span class="error_msg">${invalidAction}</span>
						
				<div id="accordion" style="clear:both;">
					<%AddTeacherService addTeacherService = new AddTeacherService();	
					List teacherList = new ArrayList<Teacher>();
					teacherList = addTeacherService.listTeachers(currentUser);
					Teacher tempTeacher = null;
					int i=0;
					Iterator teacherItr = teacherList.iterator();
					
					while(teacherItr.hasNext()) { %>
						
						<h3> <% i++; try {
							tempTeacher = (Teacher) teacherItr.next();
								} 
								catch(Exception ex){
									ex.printStackTrace();
								}%> 
								
								<%= tempTeacher.getTeacher_name() %>&nbsp; <%= tempTeacher.getTeacher_lname() %>
						</h3>
						<div>
						<form name="teacherDeleteForm<%=i%>" action="${pageContext.request.contextPath}/AddTeacherServlet" action="post">
							<input type="submit" value="" class="delete_button" alt="Delete" action=""  onclick="return confirm('Are you sure?')">
							<input type="hidden" id="teacher_id<%=i%>" name="teacher_id<%=i%>" value="<%= tempTeacher.getTeacher_id() %>" >
							<input type="hidden" id="action_type" name="action_type" value="delete">
							<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
						</form>
						<div>
							<form name="teacherUpdateForm<%=i%>" action="${pageContext.request.contextPath}/AddTeacherServlet" action="post">
								<div>
									<input type="hidden" value="<%= tempTeacher.getTeacher_id() %>" >
									<input type="hidden" id="action_type" name="action_type" value="update">
									<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
								</div>
								
								<div id="dataForm">
									<label>First Name:</label>
									<input type="text" id="teacher_fname<%=i%>" name="teacher_fname<%=i%>" value="<%=tempTeacher.getTeacher_name()%>">
								</div>
								<div id="dataForm">
									<label>Last Name:</label>
									<input type="text" id="teacher_lname<%=i%>" name="teacher_lname<%=i%>" value="<%=tempTeacher.getTeacher_lname()%>">
								</div>
								<div id="dataForm">
									<label>Email:</label>
									<input type="text" id="teacher_email<%=i%>" name="teacher_email<%=i%>" value="<%= tempTeacher.getTeacher_email_id() %>" readonly="readonly" >
								</div>
								<div id="dataForm">
									<label>Address:</label>
									<input type="text" id="teacher_address<%=i%>" name="teacher_address<%=i%>" value="<%= tempTeacher.getTeacher_address() %>">
								</div>
								<div id="dataForm">
									<label>Contact No(M):</label>
									<input type="text" id="teacher_mobile<%=i%>" name="teacher_mobile<%=i%>" value="<%= tempTeacher.getTeacher_mobile_no() %>" >
								</div>
								<div id="dataForm">
									<label>Contact No(R):</label>
									<input type="text" id="teacher_home_no<%=i%>" name="teacher_home_no<%=i%>" value="<%= tempTeacher.getTeacher_resi_no() %>" >
								</div>
								<div id="dataForm">
									<label>Skills:</label>
									<input type="text" id="teacher_skills<%=i%>" name="teacher_skills<%=i%>" value="<%= tempTeacher.getTeacher_skills() %>" >
								</div>
								<div id="dataForm">
									<label>Gender</label>
									<select name="teacher_gender_select<%=i%>" id="teacher_gender_select<%=i%>" value="<%=tempTeacher.getTeacher_gender()%>" >
											<option name="Male" value="Male">Male
											<option name="Female" value="Female">Female
										</select>
								</div>
								<div id="dataForm">
									<label>Date of Birth</label>
									<input type="text" name="teacher_dob<%=i%>" id="teacher_dob<%=i%>" value="<%= tempTeacher.getTeacher_dob() %>" placeholder="Date">
								</div>
								<div id="dataForm">
									<label>Date of Joining</label>
									<input type="text" name="teacher_doj<%=i%>" id="teacher_doj<%=i%>" value="<%= tempTeacher.getTeacher_doj() %>" placeholder="Date">
								</div>
								<div>
									<input type="submit" value="Update" class="button add_button" >
								</div>
							</form>
						</div>
						</div>
					<% } %>
				</div>
				
				
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" ></jsp:include>

			<jsp:include page="sectionMenu.jsp" />
							
			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>
	<script type="text/javascript">
		$(function(){
			$("#teacherSettings").addClass("current_page_item");
		});
	</script>

</body>
</html>